package ucuserslogic

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/common/key/userkey"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"
	"strings"

	"navi-mumbai/app/rpc/usercenter/internal/svc"
	"navi-mumbai/app/rpc/usercenter/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type FeedbackLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFeedbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FeedbackLogic {
	return &FeedbackLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户反馈
func (l *FeedbackLogic) Feedback(in *pb.FeedbackReq) (*pb.FeedbackResp, error) {
	defer utils.RecoverPanic()

	uf := usercenter.UserFeedback{
		Uid:         in.Uid,
		Content:     in.Content,
		Attachments: strings.Join(in.Attachments, "#"),
		State:       userkey.FeedbackStateCreated,
	}
	_, err := l.svcCtx.UserFeedbackModel.Insert(l.ctx, &uf)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.FeedbackResp{}, nil
}

//func (l *FeedbackLogic) after(uid int64) {
//	if uid <= 0 {
//		return
//	}
//
//	kqMsg := kqmsg.KqAddUserNotifyMsg{
//		Uid:     uid,
//		Title:   userkey.UserNotifyMsgTitleFeedbackCreated09EnIn,
//		MsgType: userkey.UserNotifyMsgTypeFeedbackCreated09,
//	}
//
//	msgContent := userkey.UserNotifyMsgContent1{
//		Text:     fmt.Sprintf(userkey.UserNotifyMsgContentFeedbackCreated09EnIn),
//		Url:      "",
//		PagePath: "",
//	}
//	var cBuf []byte
//	cBuf, err := json.Marshal(msgContent)
//	if err != nil {
//		l.Logger.Errorf("UpdateDepositResultLogic after json.Marshal(msgContent) err:%v", err)
//		return
//	}
//	kqMsg.MsgContent = string(cBuf)
//
//	var kqMsgBuf []byte
//	kqMsgBuf, err = json.Marshal(kqMsg)
//	if err != nil {
//		l.Logger.Errorf("UpdateDepositResultLogic after json.Marshal(kqMsg) err:%v", err)
//		return
//	}
//
//	err = l.svcCtx.KqAddUserNotifyMsgClient.Push(string(kqMsgBuf))
//	if err != nil {
//		l.Logger.Errorf("UpdateDepositResultLogic after Push err:%v", err)
//		return
//	}
//	return
//}
